import { Transform, Type } from 'class-transformer';
import { IsArray, IsDate, IsInt, IsOptional, IsString, ValidateNested } from 'class-validator';
import { TournamentStatusEnum } from 'src/common/constant/enums';
import { LoginUserResponseDto } from 'src/modules/auth/dto/login-user.dto';
import { CreateCategoryDto } from 'src/modules/category/dto/create-category.dto';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

/**
 * 创建赛事数据传输对象
 */
export class CreateTournamentDto {
  @ApiProperty({ type: Number, description: '赛事 ID' })
  @IsInt()
  id: number;

  @ApiProperty({ type: String, description: '赛事名称' })
  @IsString()
  name: string;

  @ApiProperty({ type: String, description: '赛事地址' })
  @IsString()
  address: string;

  @ApiProperty({ type: Date, description: '赛事开始日期' })
  @IsDate()
  @Transform(({ value }) => new Date(value))
  fromDate: Date;

  @ApiProperty({ type: Date, description: '赛事结束日期' })
  @IsDate()
  @Transform(({ value }) => new Date(value))
  endDate: Date;

  @ApiProperty({ type: Number, description: '赛事类型' })
  @IsInt()
  type: number;

  @ApiProperty({ type: Date, description: '报名开始日期' })
  @IsDate()
  @Transform(({ value }) => new Date(value))
  registrationFromDate: Date;

  @ApiProperty({ type: Date, description: '报名结束日期' })
  @IsDate()
  @Transform(({ value }) => new Date(value))
  registrationEndDate: Date;

  @ApiProperty({ type: String, description: '广告图片地址' })
  @IsString()
  adImage: string;

  @ApiProperty({ type: String, description: '详情图片地址' })
  @IsString()
  detailImage: string;

  @ApiProperty({ type: [CreateCategoryDto], description: '赛事分类列表' })
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => CreateCategoryDto)
  categories: CreateCategoryDto[];

  @IsOptional()
  user: LoginUserResponseDto;

  createBy: number;
  createTime: Date;
  updateBy: number;
  updateTime: Date;
  status: TournamentStatusEnum;

}
